using MemoryPack;

namespace Voxels {
	[MemoryPackable]
	public partial class BlockDataHolder {
		[MemoryPackIgnore]
		public virtual int SizeX {
			get { return X; }
			set { X = value; }
		}

		[MemoryPackIgnore]
		public virtual int SizeY {
			get { return Y; }
			set { Y = value; }
		}

		[MemoryPackIgnore]
		public virtual int SizeZ {
			get { return Z; }
			set { Z = value; }
		}

		[MemoryPackInclude]
		public BlockData[] Data = null;
		[MemoryPackInclude]
		public int X = 0;
		[MemoryPackInclude]
		public int Y = 0;
		[MemoryPackInclude]
		public int Z = 0;

		public BlockDataHolder() {

		}

		[MemoryPackConstructor]
		public BlockDataHolder(int x, int y, int z, BlockData[] data) {
			X = x;
			Y = y;
			Z = z;
			Data = data;
		}

		public BlockDataHolder(int sizeX, int sizeY, int sizeZ) {
			X = sizeX;
			Y = sizeY;
			Z = sizeZ;
			Data = new BlockData[sizeX * sizeY * sizeZ];
		}

		[MemoryPackIgnore]
		public BlockData this[int x, int y, int z] {
			get {
				return Data[y * Z * X + z * X + x];
			}
			set {
				Data[y * X * X + z * X + x] = value;
			}
		}

		[MemoryPackIgnore]
		public BlockData this[int pointer] {
			get {
				return Data[pointer];
			}
			set {
				Data[pointer] = value;
			}
		}
	}
}
